<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="Doc.css" rel="stylesheet"/>
<title>TreeGrid - Global</title>
</head>
<body>
<div class="Doc">


<h1>Configuration in cookies</h1>
<p>TreeGrid documentation</p>

Many TreeGrid settings are automatically saved in client browser and are persistent between sessions. So the server does <u>not</u> need to care about it.<br />
The saved settings override the settings in xml, <b>so the settings in xml are used only for the first visit</b>, when no settings are saved in cookies.<br />
When the grid layout is changed, you should increase <a href="#CfgVersion">Version</a> attribute to delete old configuration from cookies and use the new setting from xml.<br />
<i>Since 6.4 the Version is automatically generated because of setting AutoVersion='1'.</i><br />
You can suppress saving configuration completely by <tt><a href="#CfgSuppressCfg">SuppressCfg</a>='3'</tt> or you can suppress only some setting by appropriate ...<b>Lap</b> attribute (for example <tt>SortLap='1'</tt> suppresses only sorting).<br />
Configuration is saved under the grid <a href="#id">id</a> name. Grids with the same <a href="#id">id</a> will share their saved settings, but only if cookie or persistent storage is shared between those pages.<br /> 
You can control cookie setting also by API properties <a href="#CookieExpires">Grids.CookieExpires</a> and <a href="#CookieParam">Grids.CookieParam</a>.<br /><br />

The settings are saved to cookies by default. Because of cookies size limit (4096 B) you can save it to browser persistent storage instead. The persistent storage is supported only by IE 5.0+ and Firefox 2.0+. See <a href="#CfgPersistentCfg">PersistentCfg</a> attribute.<br /><br />  

It is also possible to upload to and download from server the actual configuration in XML (<tt><a href="DataUpload.htm#Upload_Type">Upload_Type</a>="Settings"</tt>) or in black box <a href="#CfgCookie">Cookie</a> (<tt><a href="DataUpload.htm#Upload_Type">Upload_Type</a>="Cookie"</tt>).<br />

<p style="font-size:130%;">To cookies (or persistent storage) is saved <b>by default</b></p>
<ul>
  <li>
  <b>Columns' visibility, positions and widths</b>
    <div class="L2">
    Attributes &lt;C Visible>, &lt;C Width> and positions of tags &lt;C> inside their section<br />
    <br />
    </div>
  </li>
  <li>
  <b>Column sections widths</b>
    <div class="L2">
    Attributes &lt;Cfg LeftWidth MidWidth RightWidth/><br />
    <br />
    </div>
  </li>
  <li>
  <b>Sort, filter, group and search</b> settings
    <div class="L2">
    &lt;Cfg Sort AutoSort Sorted/><br /> 
    &lt;Cfg Group Grouped/><br />
    &lt;Cfg SearchExpression SearchAction SearchMethod SearchCaseSensitive SearchCells SearchDefs SearchCols Searched/><br />
    &lt;Filter> cell values and cell Filter attribute and &lt;Cfg Filtered/> attribute.<br />
    <br />
    </div>
  </li>
  <li>
  <b>Configuration settings</b> - set in configuration menu and from toolbar
    <div class="L2">
    &lt;Cfg ShowDeleted Calculated AutoUpdate ShowDrag AllPages Hover SortIcons CustomScroll ScrollAction/><br />
    <br />
    </div>
  </li>
  <li>
  <b>Width and height of main tag</b> if grid <a href="GridSize.htm#CfgResizingMain">resizing</a> is permitted (css style height and width of the main tag).<br />
  <br />
  </li>
  <li>
  <b>Export</b> settings
    <div class="L2">
    &lt;Cfg ExportType, ExportFormat /><br />
    <br />
    </div>
  </li>
  <li>
  <b>Printing and PDF Export</b> settings
    <div class="L2">
    &lt;Cfg PDFPageSize, PDFPageOrientation, PDFFitPage, PDFText, PrintExpanded, PrintFiltered, PrintPageBreaks, PrintRows /><br />
    <br />
    </div>
  </li>
  <li>
  <b>Gantt chart</b> settings - attributes of Gantt type column
    <div class="L2">
    From menu: GanttCorrectDependencies, GanttCheckDependencies, GanttCorrectDependenciesFixed, GanttFixComplete, GanttStrict,<br /> 
      <div class="L1">
      GanttHideExclude, GanttBaseProof, GanttFinishProof, GanttBasePreferred, GanttFinishPreferred, GanttCheck, GanttCheckExclude<br />
      GanttMinSlack, GanttErrSlack, GanttSeparateSlack<br />
      </div>
    Zoom: GanttZoom, GanttWidth, GanttDate<br />
    Other: GanttResourcesFilter<br />
    <br />
    </div>
  </li>
</ul>
<i>For grids with more columns to decrease cookie size of saved data, you should name columns as short as possible, the best to up to three characters.</i>

<p style="font-size:130%;">To cookies (or persistent storage) you can also save:</b></p>
<ul>
  <li><b>Scroll left</b> and <b>top</b> (permit it by <tt><b>ScrollLeftLap</b>='0'</tt> / <tt><b>ScrollTopLap</b>='0'</tt>)</li>
  <li>All <b>shown</b> / <b>hidden</b> row state (row <b>Visible</b> attribute) (permit it by <a href="RowVisibility.htm#CfgSaveVisible">SaveVisible</a>)</li>
  <li>All <b>expanded</b> / <b>collapsed</b> state in tree (row <b>Expanded</b> attribute) (permit it by <a href="Tree.htm#CfgSaveExpanded">SaveExpanded</a>)</li>
  <li>All <b>expanded cells</b> (permitted by <b>ExpandCells</b> or <b>ExpandRows</b>)</li>
  <li>All <b>selected rows</b> state (row <b>Selected</b> attribute) (permit it by <a href="RowSelect.htm#CfgSaveSelected">SaveSelected</a>)</li>
  <li>All <b>pending changes</b> (changed cell values, added, deleted, moved rows) (permit it by <a href="CellEdit.htm#CfgSaveValues">SaveValues</a>)</li>
  <li><b>Custom filters</b> (permit it by <a href="Filter.htm#CfgSaveFilters">SaveFilters</a>)</li>
  <li><b>Server session</b> (IO <a href="DataCommunication.htm#IOSession">Session</a> attribute) (permit it by <a href="DataCommunication.htm#CfgSaveSession">SaveSession</a>)</li>
  <li><b>Chosen grid style</b> (&lt;Cfg <a href="CellStyle.htm#CfgStyle">Style</a>/>)</li>            
</ul>

<i>Take care about the length of saved data, especially if you are saving to cookies and not to persistent storage. You can usually permit saving of these setting only for small grids.</i><br />

<!-- id -->
<a name="id"></a>
<div class="XML">
   <u></u> <b style="margin-left:-105px;width:200px;">&lt;Cfg>&lt;treegrid/bdo></b> <i>string</i>
   <h4>id</h4> <s>[...] <i>Both letters lowercase!</i></s>
</div>
Unique ID of created TreeGrid on the page. <i>It must be string, not number, to not collide with grid indexes.</i><br />
Under this name will be stored configuration to cookies or persistent storage if not set <a href="#CfgCfgId">CfgId</a>.<br />

<!-- CfgId -->
<a name="CfgCfgId"></a>
<div class="XML">
   <u>new <b>8.1</b></u> <b>&lt;Cfg></b> <i>string</i>
   <h4>CfgId</h4> <s></s>
</div>
Under this name will be stored configuration to cookies.<br />
Useful to set when more grids on page share the same configuration.<br />

<!-- Version -->
<a name="CfgVersion"></a>
<div class="XML">
   <u>chg <b>6.4</b></u> <b>&lt;Cfg></b> <i>int</i>
   <h4>Version</h4> <s></s>
</div>
Version of data. Grid loads configuration from cookies only if the Version is the same as saved.<br /> 
Change this number whenever data structure (especially number of columns, column names and types) changes to delete old configuration saved to cookies.<br />
<i>Since <b>6.4</b> the not set Version is automatically generated when set <tt>AutoVersion='1'</tt> (it is set by default)</i><br />

<!-- AutoVersion -->
<a name="CfgAutoVersion"></a>
<div class="XML">
   <u>new <b>6.4</b></u> <b>&lt;Cfg></b> <i>bool</i>
   <h4>AutoVersion</h4> <s>[1]</s>
</div>
If set to <b>1</b>, the configuration <a href="#CfgVersion">Version</a> is automatically generated according to the actual values in XML layout.<br />
Whenever is the XML layout changed (only the attributes saved to cookies), the whole cookie is cleared and new values from XML are used.<br />
If set <a href="#CfgVersion">Version</a> or  <a href="#CfgCookie">Cookie</a> attribute, the AutoVersion is ignored.<br />
The XML attributes ignored in AutoVersion calculation: values (SaveValues), Selected (SaveSelected), Expanded (SaveExpanded), main tag width, scroll position.<br />
<i>Remember, when upgrading TreeGrid to higher version, there are often added new items to cookie, so in this case the Version changes and the old configuration is cleared when set <tt>AutoVersion='1'</tt>.</i><br />

<!-- SuppressCfg -->
<a name="CfgSuppressCfg"></a>
<div class="XML">
   <u></u> <b>&lt;Cfg></b> <i>int</i>
   <h4>SuppressCfg</h4> <s>[0]</s>
</div>
If does not use any client settings in cookies (0 - uses, 1 - does not load, 2 - does not save, 3 - nothing)<br />
If set to 4 does not load or save configuration from cookies, but still accepts and returns configuration in <a href="#CfgCookie">Cookie</a> attribute.<br />
It is good to set <tt>SuppressCfg='1'</tt> for development.<br />

<!-- DefaultCfg -->
<a name="CfgDefaultCfg"></a>
<div class="XML">
   <u>new <b>8.0</b></u> <b>&lt;Cfg></b> <i>int</i>
   <h4>DefaultCfg</h4> <s>[3]</s>
</div>
Which default configuration is saved to be available to be restored by <a href="#RestoreCfg">RestoreCfg</a><br />
<b>1</b> - default configuration in XML<br />
<b>2</b> - configuration loaded from cookies on start<br />
<b>3</b> - both<br />

<!-- DefaultCfgMenu -->
<a name="CfgDefaultCfgMenu"></a>
<div class="XML">
   <u>new <b>8.0</b></u> <b>&lt;Cfg></b> <i>int</i>
   <h4>DefaultCfgMenu</h4> <s>[1]</s>
</div>
Controls Defaults button in configuration menu.<br /> 
<b>0</b> - button will be hidden<br />
<b>1</b> - button loads default configuration in XML (must be set DefaultCfg to 1 or 3)<br />
<b>2</b> - button loads configuration loaded from cookies on start (must be set DefaultCfg to 2 or 3)<br />

<!-- PersistentCfg -->
<a name="CfgPersistentCfg"></a>
<div class="XML">
   <u><i>upd <b>11.0</b></i></u> <b>&lt;Cfg></b> <i>int</i>
   <h4>PersistentCfg</h4> <s>[0]</s>
</div>
If set, uses persistent browser cache instead of cookies for saving configuration.<br />
The persistent cache can store much more data, at least one megabyte (shared among all pages).<br />
<i>(Since 7.0)</i> This persistent cache is used as <b>localStorage</b> in IE8+, Firefox 3.0+, Chrome 4+, Safari 4+, Opera 10.5; <i>Maximal capacity 5MB</i><br />
IE6 and IE7 uses <b>userData</b> behavior with maximal capacity 128kB<br />
Firefox 2.0 uses <b>globalStorage</b> with maximal capacity 1 MB<br />
<i>In many browsers the persistent cache is <u>not</u> used when running locally on protocol file://.</i><br />
<b>0</b> - use cookies, <b>1</b> - use persistent cache if available otherwise use cookies, <b>2</b> - use only persistent cache, if available, <b>3</b> - <i>(new 11.0)</i> use <b>sessionStorage</b> if available<br />

<!-- SaveAttrs -->
<a name="CfgSaveAttrs"></a>
<div class="XML">
   <u>chg <b>8.0</b> <i>upd <b>14.1</b></i></u> <b>&lt;Cfg></b> <i>string[ ]</i>
   <h4>SaveAttrs</h4> <s></s>
</div>
Comma separated array of pairs [ident, attribute_name], like "ident1,attr1,ident2,attr2,ident3,attr3,...". <br />
The <b>ident</b> can be: a) row id to save row attribute, b) <i>since 8.0</i> column name to save column attribute or c) empty to save &lt;Cfg> attribute.<br />
<i>In case the column name collides with row id, the column is used.</i><br />
<i>Since 14.1</i> the <b>ident</b> can be keyword starting by asterisk: <b>*Col</b> to save attribute of all columns, <b>*Row</b> to save attribute of all rows, <b>*Fixed</b> to save attribute of all fixed rows (head+foot), 
<b>*Space</b> to save attribute of all solid space rows.<br />
Saves all these attribute/cell values to cookies. To save cell value, just specify its column name (as even value and row id as <b>ident</b>).<br />
You can also save any your custom row, column or grid/Cfg attribute.<br />
For example <tt>"R1,Col1,R6,Col7CanEdit,Col1,CanEdit,,Adding"</tt> = saves values R1.Col1 and R6.Col7CanEdit, column Col1 attribute CanEdit and Cfg.Adding<br />
<i><strong>!</strong> Remember, the configuration from cookies is loaded after layout xml (if present) is loaded, so to save attributes from rows loaded in data xml is impossible !</i><br />

<!-- SaveAttrsTrim -->
<a name="CfgSaveAttrsTrim"></a>
<div class="XML">
   <u></u> <b>&lt;Cfg></b> <i>int</i>
   <h4>SaveAttrsTrim</h4> <s>[50]</s>
</div>
By default are all values saved by SaveAttrs trimmed to 50 characters, because the size of cookie is small, you can change the predefined length here.<br />

<!-- Cookie -->
<a name="CfgCookie"></a>
<div class="XML">
   <u></u> <b>&lt;Cfg></b> <i>string</i>
   <h4>Cookie</h4> <s></s>
</div>
Whole configuration in string as it was saved to cookie. Use this attribute to get or return configuration saved on server by <tt><a href="DataUpload.htm#Upload_Type">Upload_Type</a>="<b>Cookie</b>"</tt>.
If this attribute is set, the configuration is loaded from it instead of cookies.<br />
Loading configuration is still affected by <a href="#CfgSuppressCfg">SuppressCfg</a> (see also its value 4), <a href="#CfgVersion">Version</a> and other such settings.<br /> 
Remember, this setting must not be modified, it must be completely the same as the setting returned by grid when saving.<br />
To send configuration to server by API you can use such code: <tt><a href="DataCommunication.htm#AjaxCall">AjaxCall</a> ("url to send", grid.<a href="DataUpload.htm#GetXmlData">GetXmlData</a>("Cookie"));</tt><br /> 
<div class="L1">or save it in API event: <tt>Grids.<a href="#OnCfgSaved">OnCfgSaved</a> = function(G,cookie) { <a href="DataCommunication.htm#AjaxCall">AjaxCall</a> ("url to send", cookie, function(){}); }</tt></div>

<!-- Grids.CookieExpires -->
<a name="CookieExpires"></a>
<div class="API">
   <u></u> <b>global prop.</b> <i>int</i>
   <h4><span style="font-style:italic;">Grids.</span>CookieExpires</h4>
   <s></s>
</div>
When configuration in cookies expires, 0 (default) never, 1 only this session, >1 after xxx seconds, or can be of type <i>Date</i> - exact expiration date.<br />

<!-- Grids.CookieParam -->
<a name="CookieParam"></a>
<div class="API">
   <u></u> <b>global prop.</b> <i>string</i>
   <h4><span style="font-style:italic;">Grids.</span>CookieParam</h4>
   <s></s>
</div>
Other cookie parameters (path, domain, secure) in string, starting with ';'. For example "; path=/".<br />

<!-- OnLoadCfg -->
<a name="OnLoadCfg"></a>
<div class="API">
   <u><i>upd <b>8.0</b></i></u> <b>API event</b> <i>bool</i>
   <h4>OnLoadCfg</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>string</i> <b>cfg</b>)</s>
</div>
Called when configuration is being loaded, return true to suppress loading. Called even if <a href="#CfgSuppressCfg">SuppressCfg</a> set.<br />
<i>(new 8.0)</i> <b>cfg</b> is cookie string that was passed to <a href="#LoadCfg">LoadCfg</a>, if any.<br />

<!-- OnCfgLoaded -->
<a name="OnCfgLoaded"></a>
<div class="API">
   <u><i>upd <b>8.0</b></i></u> <b>API event</b> <i>void</i>
   <h4>OnCfgLoaded</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>string</i> <b>cfg</b>)</s>
</div>
Called after configuration is loaded to provide own update to cfg.<br />
<i>(new 8.0)</i> <b>cfg</b> is cookie string that was passed to <a href="#LoadCfg">LoadCfg</a>, if any.<br />

<!-- OnSaveCfg -->
<a name="OnSaveCfg"></a>
<div class="API">
   <u><i>upd <b>8.0</b></i></u> <b>API event</b> <i>bool</i>
   <h4>OnSaveCfg</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>bool</i> <b>return</b>)</s>
</div>
Called when configuration is being saved to cookies, return true to suppress saving. Called even if <a href="#CfgSuppressCfg">SuppressCfg</a> set.<br />
<i>(new 8.0)</i> <b>return</b> is set to true if configuration is not saved to cookies, it is just read.<br />

<!-- OnCfgSaved -->
<a name="OnCfgSaved"></a>
<div class="API">
   <u>new <b>10.0</b></u> <b>API event</b> <i>bool</i>
   <h4>OnCfgSaved</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>string</i> <b>cfg</b>)</s>
</div>
Called when TreeGrid cookie is to be saved to browser cookies or local storage, return true to suppress saving.<br />
Here you can upload the cookie to server by AjaxCall to be later loaded to grid by <a href="#CfgCookie">Cookie</a> attribute.<br />

<!-- OnLoadCustomCfg -->
<a name="OnLoadCustomCfg"></a>
<div class="API">
   <u>new <b>8.0</b></u> <b>API event</b> <i>void</i>
   <h4>OnLoadCustomCfg</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>string</i> <b>custom</b>, <i>string</i> <b>cfg</b>)</s>
</div>
Called to load custom configuration saved by OnSaveCustomCfg.<br /> 
The <b>custom</b> is the custom configuration string. Is null, if no custom configuration was saved.<br />
<b>cfg</b> is cookie string that was passed to <a href="#LoadCfg">LoadCfg</a>, if any.<br />

<!-- OnSaveCustomCfg -->
<a name="OnSaveCustomCfg"></a>
<div class="API">
   <u>new <b>8.0</b></u> <b>API event</b> <i>string</i>
   <h4>OnSaveCustomCfg</h4>
   <s>(<i>TGrid</i> <b>grid</b>, <i>bool</i> <b>return</b>)</s>
</div>
Called to add any custom string to saved configuration. Return the string to add.<br />
<b>return</b> is set to true if configuration is not saved to cookies, it is just read.<br />

<!-- LoadCfg -->
<a name="LoadCfg"></a>
<div class="API">
   <u><i>upd <b>8.0</b></i></u> <b>API method</b> <i>void</i>
   <h4>LoadCfg</h4>
   <s>(<i>string</i> <b>cookie</b> = null)</s>
</div>
Loads configuration from cookies. Does not display any changes.<br />
<i>Since 8.0</i> it can be called also after grid is rendered to apply the configuration changes again.<br />
<i>Since 8.0</i> The <b>cookie</b> can be cookie string got by <b>SaveCfg</b> method or GetXmlData with Cookie setting.<br />

<!-- SaveCfg -->
<a name="SaveCfg"></a>
<div class="API">
   <u><i>upd <b>8.0</b></i></u> <b>API method</b> <i>string</i>
   <h4>SaveCfg</h4>
   <s>(<i>bool</i> <b>return</b> = false)</s>
</div>
Saves configuration to cookies.<br />
Call it after some custom setting changed to save changes to cookies.<br />
<i>Since 8.0</i> If set <tt><b>return</b> = true</tt>, it returns the configuration in string instead of saving it cookie. To be later used by <b>LoadCfg</b> or by <a href="#CfgCookie">Cookie</a> attribute.<br />

<!-- RestoreCfg -->
<a name="RestoreCfg"></a>
<div class="API">
   <u>new <b>8.0</b></u> <b>API method</b> <i>void</i>
   <h4>RestoreCfg</h4>
   <s>(<i>int type = 1</i>)</s>
</div>
Reloads specified configuration saved by <a href="#CfgDefaultCfg">DefaultCfg</a><br />
<b>type = 1</b> - default configuration in XML, <b>2</b> - configuration loaded from cookies on start<br />

<!-- SaveCache -->
<a name="SaveCache"></a>
<div class="API">
   <u><i>upd <b>11.0</b></i></u> <b>global func.</b> <i>void</i>
   <h4>SaveCache</h4>
   <s>(<i>string</i> <b>id</b>, <i>string</i> <b>val</b>, <i>bool</i> <b>session</b> = 0)</s>
</div>
Saves value to persistent cache according to given id. See <a href="#CfgPersistentCfg">PersistentCfg</a>.<br />
You can also redefine this function to do your own caching mechanism when set <tt>&lt;Cfg <a href="#CfgPersistentCfg">PersistentCfg</a>></tt>.<br />
<i>(Since 11.0)</i> If set <tt><b>session</b> = 1</tt>, it saves to sessionStorage instead of localStorage.<br />

<!-- LoadCache -->
<a name="LoadCache"></a>
<div class="API">
   <u><i>upd <b>11.0</b></i></u> <b>global func.</b> <i>string</i>
   <h4>LoadCache</h4>
   <s>(<i>string</i> <b>id</b>, <i>bool</i> <b>session</b> = 0)</s>
</div>
Loads and returns value from persistent cache saved by <a href="#SaveCache">SaveCache</a> function.<br />
<i>(Since 11.0)</i> If set <tt><b>session</b> = 1</tt>, it loads from sessionStorage instead of localStorage.<br />

</div>
</body>	
</html>
    